const express = require("express");
const session = require("express-session");

const app = express();
app.listen(3008, () => {
  console.log("http://127.0.0.1:3008");
});
/**
 * 1.设置session
 * 2.判断session了，不需要像cookie一样设置了，因为前面已经设置了
 */
// 这里设置之后，哪里都能用了，res可以直接用了，中间件
app.use(
  session({
    secret: "eechon",
    resave: false,
    saveUninitialized: false
  }) /* end session */
); /* end use */

app.get("/", (req, res) => {
  console.log(req.session);
  if (req.session.isLogin && req.session.isLogin == "true") {
    res.end("welcome back session");
  } else {
    req.session.isLogin = "true";
    req.session.currentUser = { name: "jack", age: 20 };
    res.end("first meet friend");
  }
});
